package edu.zut.cs.software.propertymanagement.equipment.web.spring.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;


import edu.zut.cs.software.base.web.spring.controller.GenericController;
import edu.zut.cs.software.propertymanagement.equipment.domain.Elevator;
import edu.zut.cs.software.propertymanagement.equipment.service.ElevatorManager;;

@Controller
@CrossOrigin(origins = "*")
//拦截含有的url并处理
@RequestMapping("/elevator")//1.
public class ElevatorController extends GenericController<Elevator, Long,  ElevatorManager> {
	ElevatorManager elevatorManager;

	/*
	 * 部署成功后，在浏览器中输入url 
	 * http://localhost:8080/universalStore-web/${1.}/${2.value值}
	 * 例子:http://localhost:8080/universalStore-web/favorite/index.html
	 */
	@RequestMapping(value = "/index.html", method = RequestMethod.GET)
	public ModelAndView findall() {
		List<Elevator> elevator = elevatorManager.findAll();
		//与WEB-INF中视图地址保持一致
		ModelAndView mv = new ModelAndView();
		mv.setViewName("elevator/index");
		mv.addObject("elevator",elevator);
		return mv;
	}

	@Autowired
	public void setElevatorManager(ElevatorManager elevatorManager) {
		this.elevatorManager = elevatorManager;
		this.manager = this.elevatorManager;
	}

}
